<!--
 * @Author: your name
 * @Date: 2021-07-17 23:14:58
 * @LastEditTime: 2021-07-20 17:43:19
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \project-128-10\src\module-hmmm\Boutique\Audit.vue
-->
<template>
  <div>
    <el-dialog
      title="提示"
      width="400px"
      :visible="value"
      @close="close"
      center
    >
      <div>
        <el-form
          ref="form"
          :model="auditForm"
          :rules="rules"
        >
          <el-form-item>
            <el-radio-group v-model="auditForm.chkState">
              <el-radio :label="1">通过</el-radio>
              <el-radio :label="2">拒绝</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item
            class="textarea"
            label-width="0px"
            prop="chkRemarks"
          >
            <el-input
              type="textarea"
              v-model="auditForm.chkRemarks"
            ></el-input>
          </el-form-item>
        </el-form>

      </div>
      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="close()">取 消</el-button>
        <el-button
          type="primary"
          @click="confirm()"
        >确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { choiceCheck } from '@/api/JXTK/siftBack.js'
export default {
  props: {
    value: {
      type: Boolean,
      default: false
    },
    auditId: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      auditForm: {
        chkState: 0,
        chkRemarks: ''
      },
      rules: {
        chkRemarks: [
          {
            required: true,
            message: '请输入审核意见，大佬您要审核呀',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    // 关闭弹出层的函数
    close () {
      // 清空表单数据和校验
      this.auditForm = {
        chkState: 0,
        chkRemarks: ''
      }
      this.$refs.form.resetFields()
      this.$emit('input', false)
    },
    // 点击确定按钮
    async confirm () {
      // 1、表单的兜底校验
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          //  1、调用试题审核接口
          const res = await choiceCheck({
            id: parseInt(this.auditId),
            ...this.auditForm
          })
          console.log(res)
          // 2、提示用户审核成功
          this.$message({
            message: '审核成功',
            type: 'success'
          })
          // 3、更新列表数据
          // 调用table父组件中的更新列表的方法(技术点：子传父自定义事件)
          this.$emit('upTableList')
          // 4、关闭弹出层
          this.close()
        }
      })
    }
  }
}
</script>

<style>
/* .textarea {
  margin-top: 20px;
} */
</style>
